<template>
	<view class="guess-section">
		<view
			v-for="(item, index) in goodsList" :key="index"
			class="guess-item"
			@click="navToDetailPage(item)"
		>
			<view class="image-wrapper"><image :src="item.image" mode="aspectFill"></image></view>
			<text class="title clamp">{{item.title}}</text>
			<text class="price">￥{{item.price}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goodsList:[]
			}
		},
		onLoad() {
			this.loadData();
		},
		methods: {
			async loadData() {
				let carouselList = await this.$api.json('carouselList');
				this.titleNViewBackground = carouselList[0].background;
				this.swiperLength = carouselList.length;
				this.carouselList = carouselList;
				
				let goodsList = await this.$api.json('goodsList');
				this.goodsList = goodsList || [];
			},
			//详情页
			navToDetailPage(item) {
				//测试数据没有写id，用title代替
				let id = item.title;
				uni.navigateTo({
					url: `/pages/category/product/product?id=${id}`
				})
			},
		}
	}
</script>

<style lang="scss">
	.guess-section{
		margin-top:20rpx;
		display:flex;
		flex-wrap:wrap;
		padding: 0 20rpx;
		.guess-item{
			background: #fff;
			border-radius:10rpx;
			overflow: hidden;
			display:flex;
			flex-direction: column;
			width: 48%;
			padding-bottom: 30rpx;
			margin-bottom: 4%;
			&:nth-child(2n+1){
				margin-right: 4%;
			}
		}
		.image-wrapper{
			width: 100%;
			height: 330rpx;
			image{
				width: 100%;
				height: 100%;
				opacity: 1;
			}
		}
		.title{
			font-size:28rpx;
			color: $font-color-dark;
			line-height: 80rpx;
			padding: 0 20rpx;
		}
		.price{
			font-size:32rpx;
			color: $uni-color-primary;
			line-height: 1;
			padding: 0 20rpx;
			font-weight: bold;
		}
	}
</style>
